﻿<%@ Page Title="店铺规划SKC" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />

    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/enterpriseLayout/makePlan.css" rel="stylesheet">
    <link href="../assets/css/plugins/stepper/stepper.widget.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <style>
        .condition, .module-info .form-group {
            padding: 3px 0;
        }

        .module-info .form-group {
            margin: 0;
            overflow: hidden;
        }

        .module-info .form-group .control-label, .module-info .form-group .form-control {
            float: left;
        }

        .inmodal .modal-body {
            padding: 10px 10px 8px 10px;
        }

        #sizeTable {
            border-left: 1px solid #dfdfdd;
            border-top: 1px solid #dfdfdd;
        }

        #sizeTable th, #sizeTable td {
            width: 40px;
            text-align: center;
            border-right: 1px solid #dfdfdd;
            border-bottom: 1px solid #dfdfdd;
            height: 30px;
            line-height: 30px;
        }

        #sizeTable .inputSize {
            width: 100%;
            height: 100%;
            border: 0;
            text-align: center;
            margin: 0;
        }

        @media (min-width: 768px) {
            .modal-dialog {
                width: 768px;
                margin: 30px auto;
            }
        }

        .condition, .condition-title {
            border-bottom: 1px solid #dfdfdd;
        }
        /*所有表格行高缩小*/
        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            padding: 0px;
        }
        .border-bottom-bold {
            border-bottom: 0px !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container">
            </div>
            <div class="condition">
                <label>关键字:</label>
                <input class="form-control input-w140" id="input-keys" placeholder="输入店铺名称或编号" />
                <label>省份</label>
                <select class="form-control input-w160" id="serarch-province">
                    <option value="">请选择</option>
                </select>
                <label>城市</label>
                <select class="form-control input-w160" id="serarch-city">
                    <option value="">请选择</option>
                </select>
            </div>
            <div style="overflow: auto; background: #fff; padding: 0 1px;">
                <div class="tb-head-container" id="thc1">
                        <table class="loadTable">
                            <thead></thead>
                        </table>
                    </div>
                    <div class="tb-body-container" id="tbc1">
                        <table class="loadTable">
                            <tbody class="loadList">
                            </tbody>
                        </table>
                      
                    </div>
            </div>
            <div class="pageControl"></div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
<script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
<script src="../assets/js/framework.js"></script>
<script src="../assets/img/validate/learunui-validator.js"></script>
<script>
    $(document).ready(function () {
        var ModuleID = Y.getUrlParam("ModuleID");
        var page = 1;
        var isCreate = true;
        //获取按钮
        commonUtil.loadBtnList(ModuleID, function () {
        });

        //加载省份
        var provinceList = [];
        var proName = '';
        Y.API2('OdsErpBasArea', 'GetAllOdsErpBasAreaList', {}, function (data) {
            if (data.Success == false) {
                swal(data.Message, '', 'error');
            } else {
                data.map(function (item) {
                    $('#serarch-province').append('<option value="' + item[0].ParentID + '">' + item[0].ParentName + '</option>');
                    $('#province').append('<option value="' + item[0].ParentID + '">' + item[0].ParentName + '</option>');
                    var tempList = [];
                    item.map(function (it) {
                        tempList.push({
                            AreaID: it.AreaID,
                            AreaName: it.AreaName
                        })
                    })
                    provinceList.push({
                        ParentID: item[0].ParentID,
                        ParentName: item[0].ParentName,
                        List: tempList
                    })
                })
            }
        })

        //省份变更
        var changeProvince = function (pEl, cEl) {
            var value = pEl.val();
            cEl.html('<option value="">请选择</option>');
            if (value == '')
                return false;
            var html = '';
            provinceList.map(function (item) {
                if (item.ParentID == value) {
                    item.List.map(function (it) {
                        html += '<option value="' + it.AreaID + '">' + it.AreaName + '</option>';
                    })
                    cEl.append(html);
                    return false;
                }
            })
        }
        $('#serarch-province').change(function () {
            changeProvince($(this), $('#serarch-city'));
        })
        $('#province').change(function () {
            changeProvince($(this), $('#city'));
        })

        //处理表头
        var headChildren = [
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">仓库ID</span>', tdId: '', tdClass: 'diy-td-w100 hide' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:80px;">大类ID</span>', tdId: '', tdClass: 'diy-td-w80 hide' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">中类ID</span>', tdId: '', tdClass: 'diy-td-w100 hide' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">小类ID</span>', tdId: '', tdClass: 'diy-td-w100 hide' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">店铺编号</span>', tdId: '', tdClass: 'diy-td-w100' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">店铺名称</span>', tdId: '', tdClass: 'diy-td-w200' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:80px;">大类</span>', tdId: '', tdClass: 'diy-td-w80' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">中类</span>', tdId: '', tdClass: 'diy-td-w100' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:150px;">小类</span>', tdId: '', tdClass: 'diy-td-w150' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:150px;">细类</span>', tdId: '', tdClass: 'diy-td-w150' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">现有SKC</span>', tdId: '', tdClass: 'diy-td-w100' },
                { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:150px;">标准陈列SKC</span>', tdId: '', tdClass: 'diy-td-w150' },
        ];

        tableControl.initThead('#thc1 .loadTable', [{
            trClass: '', children: headChildren
        }]);

        //多选框样式
        $(".tb-head-container .loadTable").icheckAll({
            checkObj: ".checkItem",//表格下面的选择控件对象 选择器
            checkAllObj: "#checkAll",//全选 选择器
            clickoutBoxCheck: true,//点击行 不选中
        });

        //获取浏览器类型
        var sUserAgent = navigator.userAgent.toLowerCase();
        //计算容器大小
        var calcContainer = function () {
            //计算表格高度
            $('.tb-body-container').height(
                $('.right-side').height() - $('.condition').outerHeight() -
                $('.tb-head-container').outerHeight() - (sUserAgent.indexOf('chrome') > -1 ? 70 : 79));
            //计算表格宽度
            //		$('.tb-body-container').width($('.tb-head-container .loadTable').width());
        }
        $(window).resize(function () {
            //重新计算容器高度
            calcContainer();
        })

        //计算差异值
        var pageList = [];

        var loadList = function () {
            if ($('#checkAll').is(':checked')) {
                $('#checkAll').parent().removeClass('checked');
                $('#checkAll').prop("checked", false);
            }
            pageControl.init('DWShopStandardSKC', 'GetShopStandardSKCList', {
                ProID: $('#serarch-province').val(),
                CityID: $('#serarch-city').val(),
                Keys: $("#input-keys").val(),
                Page: page,
                Size: 2,
                needLayer: true,
                alwaysCallBack: function () {
                    $('#tbc1 .loadList').empty();
                }
            }, function (result) {
                page = result.page;
                pageList = [];
                var tBody = [];
                if (!Y.checkNull(result.data)) {
                    var rdi = result.data.Items;
                    pageList = rdi;
                    if (rdi.length > 0) {
                        rdi.map(function (item, it) {
                            item.kindList.map(function (kl, k) {
                                kl.modelList.map(function (ml, m) {
                                    ml.itemList.map(function (il, i) {
                                        il.subItemList.map(function (sil, si) {
                                            var tempChild = [];
                                            if (m == 0 && i == 0 && si == 0) {

                                                tempChild = [
                                                    { tdText: '', c: 0, r: kl.modelLength, tdHtml: '<span style="display:inline-block; width:100px;">' + (item.StockID || ' ') + '</span>', tdId: '', tdClass: 'StockID diy-td-w100 border-bottom-bold hide' },
                                                    { tdText: '', c: 0, r: kl.modelLength, tdHtml: '<span style="display:inline-block; width:80px;">' + (kl.KindID || ' ') + '</span>', tdId: '', tdClass: 'KindID diy-td-w80 border-bottom-bold hide' },
                                                    { tdText: '', c: 0, r: kl.modelLength, tdHtml: '<span style="display:inline-block; width:100px;">' + (item.ShopCode || ' ') + '</span>', tdId: '', tdClass: 'ShopCode diy-td-w100 border-bottom-bold' },
                                                    { tdText: '', c: 0, r: kl.modelLength, tdHtml: '<span style="display:inline-block; width:200px;">' + (item.ShopName || ' ') + '</span>', tdId: '', tdClass: 'ShopName diy-td-w200 border-bottom-bold' },
                                                    { tdText: '', c: 0, r: kl.modelLength, tdHtml: '<span style="display:inline-block; width:80px;">' + (kl.KindName || ' ') + '</span>', tdId: '', tdClass: 'KindName diy-td-w80 border-bottom-bold' },
                                                ];
                                            }
                                            if (i == 0 && si == 0) {

                                                tempChild.push({ tdText: '', c: 0, r: ml.itemLength, tdHtml: '<span style="display:inline-block; width:100px;">' + (ml.ModelID || ' ') + '</span>', tdId: '', tdClass: 'ModelID diy-td-w100 border-bottom-bold hide' });
                                                tempChild.push({ tdText: '', c: 0, r: ml.itemLength, tdHtml: '<span style="display:inline-block; width:100px;">' + (ml.ModelName || ' ') + '</span>', tdId: '', tdClass: 'ModelName diy-td-w100 border-bottom-bold' });

                                            }
                                            if (si == 0) {

                                                tempChild.push({ tdText: '', c: 0, r: il.subItemLength, tdHtml: '<span style="display:inline-block; width:100px;">' + (il.ItemID || ' ') + '</span>', tdId: '', tdClass: 'ItemID diy-td-w100 border-bottom-bold hide' });
                                                tempChild.push({ tdText: '', c: 0, r: il.subItemLength, tdHtml: '<span style="display:inline-block; width:150px;">' + (il.ItemName || ' ') + '</span>', tdId: '', tdClass: 'ItemName diy-td-w150 border-bottom-bold' });

                                            }
                                            tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:150px;">' + (sil.SubItem || ' ') + '</span>', tdId: '', tdClass: 'SubItem diy-td-w150 border-bottom-bold' });
                                            tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:100px;">' + (sil.HaveSKC || ' ') + '</span>', tdId: '', tdClass: 'HaveSKC diy-td-w100 border-bottom-bold' });
                                            tempChild.push({
                                                tdText: '',
                                                c: 0,
                                                r: 0,
                                                tdHtml:
                                                    '<input type="number" style="display:inline-block; width:150px; border:0px; text-align:center;" ' +
                                                        'tap-StockID = "' + (item.StockID || " ") +
                                                        '" tap-KindID = "' + (kl.KindID || " ") +
                                                        '" tap-ModelID = "' + (ml.ModelID || " ") +
                                                        '" tap-ItemID = "' + (il.ItemID || " ") +
                                                        '" tap-SubItem = "' + (sil.SubItem || " ") +
                                                        '" tap-StandardSKC = "' + (sil.StandardSKC || " ") +
                                                        '" value=' + (sil.StandardSKC || " ") +
                                                        '>',
                                                tdId: '',
                                                tdClass: 'StandardSKC diy-td-w150 border-bottom-bold'
                                            });

                                            var tempTr = {
                                                trClass: 'gradeX footable-even' + ' ',
                                                children: tempChild
                                            };
                                            tBody.push(tempTr);
                                        });
                                    });
                                });
                            });
                        });
                        tableControl.initTbody('#tbc1 .loadTable', (tBody.length > 0 ? tBody : null), 0, null);
                        calcContainer();
                        changeSKC();
                        return false;
                    }
                    $('#tbc1 .loadList').append(
                        '<tr><td style="width:' + $('#thc1 th:first').width() + 'px;"><i class="fa fa-frown-o"></i></td>' +
                        '<td style="width:' + ($('#thc1 .loadTable').width() - $('#thc1 th:first').width()) + 'px;">无数据</td></tr>');
                    calcContainer();
                }
            })
        }
        loadList();

        //导入

        //批量添加任务
        $(".btns-container").on("click", '#importBtn', function () {
            var conditionsArr = [];
            var proID = $('#serarch-province').val();
            if (!Y.checkNull(proID)) {
                conditionsArr.push({ column: "area.ParentID", value: proID, operator: "=", connector: "and" });
            }
            var cityID = $('#serarch-city').val();
            if (!Y.checkNull(cityID)) {
                conditionsArr.push({ column: "shop.AreaID", value: cityID, operator: "=", connector: "and" });
            }
            var keys = $("#input-keys").val();
            if (!Y.checkNull(keys)) {
                conditionsArr.push({ column: "KeyStart", value: keys + "KeyEnd", operator: "=", connector: "and" });
            }
            conditionsArr = JSON.stringify(conditionsArr);
            $.ImportExcelTemplate({
                filetype: 'DWSHOPSTANDARSKC',
                filename: '店铺规划SKC',
                state: 'hasInfo',
                action: 'ImportTemplate',
                conditions: encodeURIComponent(conditionsArr),
                after: function () {
                    //回调方法
                    page = 1;
                    loadList();
                }
            });
        });
        inputControl.init({
            els: ['.inputSize'],
            container: '#sizeTable',
            inputEvent: 'blur',
            defValue: '',
            isNum: true,
            inputLength: 5,
            max: 100,
            min: 0,
        });
        //查询按钮
        $(".btns-container").on('click', '#btn-search', function () {
            page = 1;
            loadList();
        })


        //编辑数量
        var changeSKC = function () {
            //监听数据
            $('input[tap-StandardSKC]').change(function () {
                var skc = parseInt($(this).val());

                if (skc < 0) {
                    swal('不能为负数', '', 'error');
                    return false;
                }
                if (/\D/g.test(skc) || /^$/.test(skc)) {
                    swal('请不要输入非数字内容', '', 'error');
                    return false;
                }

                var sendData = {
                    StockID: $(this).attr('tap-StockID'), //	店铺ID
                    KindID: $(this).attr('tap-KindID'), //	货架ID
                    ModelID: $(this).attr('tap-ModelID'),
                    ItemID: $(this).attr('tap-ItemID'),
                    SubItem: $(this).attr('tap-SubItem'),
                    StandardSKC: skc, //数量
                }
                layer.msg('玩命加载中……', {
                    icon: 16,
                    shade: 0.5,
                    time: 0,
                    maxWidth: 200
                });
                Y.API2('DWShopStandardSKC', 'ModifyShopStandardSKC', sendData, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal("编辑成功", '', 'success');
                        //刷新列表
                        page = 1;
                        loadList();
                    }
                });

            });
        }
    })
</script>
</asp:Content>

